const http = require('http')
const fs = require('fs')
const childProcess = require('child_process');


const server = http.createServer((req, res) => {
    console.log(req.url)
    fs.readFile(`./${req.url}`, (error, data) => {
        if (error) {
            res.write('404')
            res.write('Not Found')
        } else {
            res.write(data)
        }
        res.end()
    })
})
const port = 8080
const hostname = 'localhost'
// 开启监听
server.listen(port, hostname, () => {
    // 在命令行打印运行结果
    console.log(`Server running at http://${hostname}:${port}/`);
    // 使用默认浏览器打开地址
    childProcess.exec(`start http://${hostname}:${port}/`);
});